Demand demand results from demand rate ugens


superclass: MultiOutUGen


Demand.ar(trig, reset, [..ugens..])

Demand.kr(trig, reset, [..ugens..])



When there is a trigger at the trig input, a value is demanded each ugen in the list and output. The unit generators in the list should be 'demand' rate.

When there is a trigger at the reset input, the demand rate ugens in the list are reset.


trig - trigger. Can be any signal. A trigger happens when the signal changes from non-positive to positive.

reset - trigger. Resets the list of ugens when triggered.


see also: Duty, TDuty


Note: By design, a reset trigger only resets the demand ugens; it does not reset the value at Demand's output. Demand continues to hold its value until the next value is demanded, at which point its output value will be the first expected item in the list.

// for Demand to jump to the start value upon receipt of a reset trigger, 

// one can add (+) the two triggers together:


(

a = { |t_trig, t_reset|

var d = Demand.kr(t_trig + t_reset, t_reset, Dseries(0, 1, inf));

d.poll(t_trig + t_reset);

0.0;

}.play

)


// do this a few times -- the demand value should increase by 1 each time

a.set(\t_trig, 1);


a.set(\t_reset, 1); // goes immediately back to 0



// if d = Demand.kr(t_trig, t_reset, Dseries(0, 1, 10000000)), the reset trigger would output its old value and the new value would appear only on the next t_trig.




Another Note: One demand ugen represents a single stream of values, so that embedding the same ugen twice calls this stream twice. To isolate a demand ugen, use a function:


(

{

var a, b, t = Impulse.kr(2);

a = { Dseq([1, 2, 3, 4, 5], inf) } * 100;

b = a + 1;

Demand.kr(t, 0, [a, b]).poll(t)

}.play

);




Examples


(

{ 

var trig, seq, freq;

trig = Impulse.kr(24);

seq = Drand([Dseq((1..5).mirror1, 1), Drand((4..10), 8)], 2000);

freq = Demand.kr(trig, 0, seq * 100);

SinOsc.ar(freq + [0,0.7]).cubed.cubed.scaleneg(MouseX.kr(-1,1)) * 0.1;

}.play;

)


(

{ 

var trig, seq, freq;

trig = Impulse.kr(12);

seq = Drand([Dseq((1..5).mirror1, 1), Drand((4..10), 8)], 2000) * Drand([1,2,4,8],2000);

freq = Demand.kr(trig, 0, seq * 100);

SinOsc.ar(freq + [0,0.7]).cubed.cubed.scaleneg(MouseX.kr(-1,1)) * 0.1;

}.play;

)





(

{

var freq, trig, reset, seq;

trig = Impulse.kr(10);

seq = Diwhite(60, 72, inf).midicps; 

freq = Demand.kr(trig, 0, seq);

SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;

}.play;

)


(

{

var freq, trig, reset, seq;

trig = Impulse.kr(10);

seq = Dseq([72, 75, 79, Drand([82,84,86])], inf).midicps; 

freq = Demand.kr(trig, 0, seq);

SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;

}.play;

)



(

{

var freq, trig, reset, seq;

trig = Impulse.kr(10);

seq = Dswitch1(

[

Diwhite(60, 72, inf), 

Dseq([72, 75, 79, Drand([82,84,86])], inf)

], 

LFPulse.kr(0.2)

); 

freq = Demand.kr(trig, 0, seq.midicps);

SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;

}.play;

)



(

{

var freq, trig, reset, seq1, seq2;

trig = Impulse.kr(10);

seq1 = Drand([72, 75, 79, 82] - 12, inf).midicps; 

seq2 = Dseq([72, 75, 79, Drand([82,84,86])], inf).midicps; 

freq = Demand.kr(trig, 0, [seq1, seq2]);

SinOsc.ar(freq + [0,0.7]).cubed.cubed * 0.1;

}.play;

)


(

{

var trig, seq;

trig = Impulse.kr(8);

seq = Drand([

Dseq([4,0,0,1,2,1,0,1]),

Dseq([4,0,2,0,1,0,1,1]),

Dseq([4,0,0,2,0,0,1,1]),

Dseq([4,0,1,2,0,1,2,0]),

Dseq([4,1,1,1,2,2,3,3]),

Dseq([4,1,0,1,0,1,0,1])

], inf);

trig = Demand.kr(trig, 0, seq * 0.4) * trig;

{LPF.ar(PinkNoise.ar, 5000)}.dup * Decay.kr(trig, 0.5);

}.play;

)